package com.wimcorp.magic.abilities;

import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.Table;

import com.wimcorp.magic.abilities.trigger.AbilityTrigger;
import com.wimcorp.magic.cards.PlayingCard;
import com.wimcorp.magic.exception.CastException;
import com.wimcorp.magic.input.Target;

/**
 * example {target: 'SELF', amount:'2'}
 * 
 * target options : SELF,OPPONENT
 * 
 * amount
 */
@Entity
@Table(name = "drawcards", schema = "abilities")
public class DrawCards extends Ability {

	private int amount;

	protected DrawCards() {
	}

	public DrawCards(AbilityTrigger trigger) {
		super(trigger);
	}

	public DrawCards(DrawCards ability) {
		super(ability);
		this.amount = ability.getAmount();
	}

	@Override
	protected void executeAbility() throws CastException {
		List<PlayingCard> cards = new ArrayList<>();
		switch (getTarget()) {
		case SELF:
			cards = getPlayer().getDeck().drawCards(amount);
			for (int i = 0; i < amount; i++) {
				getPlayer().getHand().add(cards.get(i));
			}
			break;
		case OPPONENT:
			cards = getPlayer().getOpponent().getDeck().drawCards(amount);
			for (int i = 0; i < amount; i++) {
				getPlayer().getHand().add(cards.get(i));
			}
			break;
		}
	}

	public int getAmount() {
		return amount;
	}

	@Override
	public DrawCards clone() {
		return new DrawCards(this);
	}

	public void setAmount(int amount) {
		this.amount = amount;
	}

}
